import tensorflow as tf2
tf = tf2.compat.v1
tf.disable_eager_execution()

# ==== 计算 1+2+3...+10 ====

value = tf.Variable(0, name='value')
one = tf.constant(1)
# 自增变量
update_value = tf.assign(value, value + one)
# 存放结果的变量
result = tf.Variable(0, name='result')
# 累加运算
accumulation = tf.assign(result, result + value)

sess = tf.Session()
sess.run(tf.global_variables_initializer())
for _ in range(10):
    sess.run(update_value)
    sess.run(accumulation)
print(sess.run(result))
